package com.wswy.wzcx.module.validator

import android.app.Activity
import com.che.libcommon.utils.ToastUtils
import com.che.libcommon.utils.optional.function.Consumer
import com.wswy.wzcx.model.resp.CaptchaData

class ImgCaptchaValidator(private val activity: Activity,private val data: CaptchaData?) : IValidator {

    private var dialog: ImgCaptchaDialog? = null

    override fun startVerify(ticketConsumer: Consumer<ValidatorResult>?) {

        dialog = ImgCaptchaDialog(activity,data).apply {

            validCallback = {

                if (it.isNullOrEmpty()){
                    ticketConsumer?.consume(null)

                }else{
                    ticketConsumer?.consume(ValidatorResult(IValidator.IMG,it))
                }
                dismiss()
            }

            show()
        }

    }

    override fun onDestroy() {
        dialog?.dismiss()
    }

}